<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>搜索</title>
    <style>
        #container{
            width: 175px;
            /* height: 400px; */
            border: 1px solid #ccc;
            display: none;
            position: relative;
            top: -1px;
        }
        #container p:hover{
            cursor: pointer;
            color: blue;
        }

    </style>
    <script src="jquery1.9/jquery-1.9.0.min.js"></script>
    <script>
         function doGetScript2() {
            let wd = $("#wd").val();
            let url = "./service/doGetScript.php?functionName=showMsg&id=1";
            url = "https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=33423,1420,33419,33306,31660,33287,33351,33313,33312,33311,33310,33163,33309,26350,33308,33307,33265,33389,33381,33370&cb=showMsg&wd="+wd;
            $.getScript(url, (script, textStatus, jqXHR)=>{
                // console.log("请求成功");
                // console.log("script:", script);
                // console.log("textStatus:", textStatus);
                // console.log("jqXHR:", jqXHR);
            });
            var mydiv=document.getElementById("container");
            mydiv.innerHTML="";
        }
        function showMsg(data) {
            // console.log("showMsg:", data.g);
            var mydiv=document.getElementById("container");
            if(data.g){
            for(let i=0;i<(data.g).length;i++){
                console.log(data.g[i].q);
                var newP=document.createElement("p");
                newP.innerHTML=data.g[i].q;
                mydiv.appendChild(newP);
            }
            }else{
                mydiv.style.display="none";
            }
        }

        $(function(){
            $("#wd").keyup(function(){
                let wd = $("#wd").val();
                let url = "./service/doGetScript.php?functionName=showMsg&id=1";
                url = "https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=33423,1420,33419,33306,31660,33287,33351,33313,33312,33311,33310,33163,33309,26350,33308,33307,33265,33389,33381,33370&cb=showMsg&wd="+wd;
                $.getScript(url, (script, textStatus, jqXHR)=>{
                    console.log("请求成功");
                    console.log("script:", script);
                    console.log("textStatus:", textStatus);
                    console.log("jqXHR:", jqXHR);
                });
                var mydiv=document.getElementById("container");
                mydiv.style.display="block";
                mydiv.innerHTML="";
            });
        });
    </script>
</head>
<body>
    <input type="text" id="wd" >
    <input type="button" value="doGetScript2" onclick="doGetScript2()">
    <div id="container">

    </div>
</body>
</html>